package com.zhss.demo.zk;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
import org.apache.zookeeper.CreateMode;

import java.nio.charset.StandardCharsets;

public class CuratorDemo {
    public static void main(String[] args) throws Exception {
//        CuratorFramework client = ZkLockHelp.getClient();
//        client.create().creatingParentContainersIfNeeded().forPath("/path");
//        client.create().creatingParentContainersIfNeeded().forPath("/path2", "path2".getBytes(StandardCharsets.UTF_8));
//
//        client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/persistent_sequential", "persistent_sequential".getBytes(StandardCharsets.UTF_8));
//        client.create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/p1/persistent_sequential", "/p1/persistent_sequential".getBytes(StandardCharsets.UTF_8));
//
//        ZkLockHelp.shutdown();

        InterProcessMutex cjm_tmp_clock = ZkLockHelp.getReentrnLock("cjm_tmp_clock");
        cjm_tmp_clock.acquire();

        new Thread(() -> {
            try {
                cjm_tmp_clock.acquire();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();

        ZkLockHelp.shutdown();
    }
}
